/*
 * Copyright (c) 2018 Hitevision
 */

package tw.com.hitevision.whiteboard.android.display;

import android.content.Context;

import com.hht.sdk.client.APIManager;
import com.hht.sdk.system.HHTSystemManager;

public class DisplayControlImpl implements DisplayControl {
    private boolean isRunning;

    private RectTouchManager rectTouch;

    DisplayControlImpl(Context context) {
        isRunning = false;
    }

    /**
     * Returns {@code true} if screen control is supported on current device.
     */
    @Override
    public boolean isSupported(Context context) {
        return true;
    }

    @Override
    public boolean isRunning() {
        return isRunning;
    }

    @Override
    public void setDisabledBounds(int x, int y, int width, int height) {
        // no-op
    }

    @Override
    public void start(Context context) {
        APIManager.connectionService(context);
        rectTouch = new RectTouchManager(new HHTSystemManager(context));
        rectTouch.setSourceDisableTouch();
    }

    @Override
    public void startFromOnResume(Context context) {
        start(context);
    }

    @Override
    public void stop(Context context) {
        if (rectTouch != null) {
            rectTouch.setSourceEnableTouch();
        }
        APIManager.disconnectService(context);
    }

    @Override
    public void cancel(Context context) {
        if (rectTouch != null) {
            rectTouch.setSourceEnableTouch();
        }
        APIManager.disconnectService(context);
    }

    @Override
    public boolean isX9DeviceType() {
        return false;
    }
}
